package com.thejavacode.quartz;

import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.job.SimpleJob;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;

public class SpringQuartzJob{
	
	/** Este objeto es el encargado de lanzar una tarea */
    private SimpleJobLauncher launcher;
    
    /** La tarea a ejecutar. */
    private SimpleJob job;

	public SpringQuartzJob() {}

	public void setLauncher(SimpleJobLauncher launcher) {
		this.launcher = launcher;
	}

	public void setJob(SimpleJob job) {
		this.job = job;
	}

	public void execute() throws Exception {
		JobParametersBuilder builder = new JobParametersBuilder();
//        builder.addDate("Ejecucion", new Date());
//        builder.addString("jobName", "Imprimir planetas por consola");
        JobParameters parameters = builder.toJobParameters();
        
        try {
			launcher.run(job, parameters);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
	}

}
